package org.zjx.action;

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef;
import org.zjx.action.basic.ScreenshotAction;
import org.zjx.core.impl.StartWindow;
import org.zjx.strategy.IStrategy;
import org.zjx.strategy.StrategyFactory;
import org.zjx.core.IWindow;

public class StrategyAction extends Action {

    public StrategyAction(IWindow targetWindow) {
        super(targetWindow, false);
    }

    @Override
    protected void doExecute() {

        if (!targetWindow.getHwnd().equals(new WinDef.HWND(Pointer.NULL))){
            ScreenshotAction screenshotCommand = targetWindow instanceof StartWindow ? new ScreenshotAction(targetWindow, true) : new ScreenshotAction(targetWindow);
            screenshotCommand.execute();
        }


        IStrategy strategy = StrategyFactory.getInstance()
                .selectAndExecuteStrategy(targetWindow);

        Action nextCommand = strategy.analyze(targetWindow);
        if (nextCommand != null) {
            targetWindow.submitAction(nextCommand);
        }
    }
}
